package com.shi.yoyoshop.controller;

import com.shi.yoyoshop.bean.Goods;
import com.shi.yoyoshop.bean.Type;
import com.shi.yoyoshop.service.GoodsService;
import com.shi.yoyoshop.service.OrderService;
import com.shi.yoyoshop.service.TypeService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class IndexController {

    @Resource
    private TypeService typeService;

    @Resource
    private GoodsService goodsService;

    @Resource
    private OrderService orderService;

    @GetMapping("/")
    public String index() {
        return "/index.jsp";
    }

    /**
     * 用户端首页
     *
     * @param request
     * @return
     */
    @GetMapping("/index/index")
    public String indexPage(HttpServletRequest request) {
        // 商品分类列表
        List<Type> typeList = typeService.getTypeList();
        request.getSession().setAttribute("typeList", typeList);
        // 今日精选推荐
        List<Goods> goodsList1 = goodsService.getGoodsListByHotTypeId(1);
        request.setAttribute("top1List", goodsList1);
        // 热销推荐
        List<Goods> goodsList2 = goodsService.getGoodsListByHotTypeId(2);
        request.setAttribute("top2List", goodsList2);
        List<Goods> goodsList3 = goodsService.getGoodsListByHotTypeId(3);
        // 新品推荐
        request.setAttribute("top3List", goodsList3);
        request.setAttribute("flag", 1);

        return "/index/index.jsp";
    }

}
